﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace DBComparer
{
    [DefaultEvent("onListLoaded")]
    [DefaultProperty("Objects")]
    public partial class SPList : UserControl
    {
        Common.Connection _Connection = null;
        SortedList<string, string> _Objects = null;

        DataAccess.Methods.Type _type = DataAccess.Methods.Type.SP;

        public DataAccess.Methods.Type ObjectType
        {
            get { return _type; }
            set { _type = value; }
        }

        public event EventHandler onListLoaded;

        #region Properties
        
        internal Common.Connection Connection
        {
            get { return _Connection; }
            set { _Connection = value;
            //Reload();
            }
        }
       
        public SortedList<string, string> Objects
        {
            get { return _Objects; }
            set { _Objects = value; }
        }
       
        #endregion

        public SPList()
        {
            InitializeComponent();

            Objects = new SortedList<string, string>();
        }

        public void Reload() 
        {
            chk.Items.Clear();
            try
            {
                Objects.Clear();
            }
            catch (Exception)
            {
                
            }

            if (Connection!=null)
            {
                Objects = new DataAccess.Methods().GetSP(Connection.GetConnection(), _type);

                foreach (string s in Objects.Keys)
                    chk.Items.Add(s);  
                
                lblCount.Text = chk.Items.Count.ToString();

                if (onListLoaded!=null)
                    onListLoaded(new object(), EventArgs.Empty);
            }
        }

    }
}
